﻿using System;
using System.Web.Mvc;
using AprenderComendo.Infrastructure.Persistence;
using AprenderComendo.Models;

namespace AprenderComendo.Controllers
{
    public class PresentationController : Controller
    {
        private IPresentationRepository presentationRepository;

        public PresentationController(IPresentationRepository presentationRepository)
        {
            this.presentationRepository = presentationRepository;
        }

        //
        // GET: /Presentation/Detail/Name

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Detail(string name)
        {
            var presentation = presentationRepository.FindBy(name);
            return View(presentation);
        }

        //
        // GET: /Presentation/New
        public ActionResult New()
        {
            return View();
        }

        //
        // POST: /Presentation/Create
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create()
        {
            var presentation = new Presentation(Request.Form["Title"].ToString(), DateTime.Parse(Request.Form["Date"].ToString()), null);
            presentationRepository.Save(presentation);
            return RedirectToAction("Index", "Home");
        }

        //GET: /Presentation/List/Criteria
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult List()
        {
            var presentations = (Request.QueryString["searchbox"] == null ? presentationRepository.FindAll() : presentationRepository.FindBy(Request.QueryString["searchbox"]));
            return View(presentations);
        }

    }
}
